package com.neuedu.shixun.hospital2.controller;
import com.neuedu.shixun.hospital2.entity.User;
import com.neuedu.shixun.hospital2.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@Slf4j
@RestController
@RequestMapping("/user")
@CrossOrigin
public class UserController{
    @Autowired
    private UserService userService;
    @GetMapping("/getUser")
    public List<User> getUser(){
        List<User> list=userService.getUser();
        return list;
    }
    @PostMapping("/updateUser")
    public User updateUser(@RequestBody User user){
      User user1= userService.saveUser(user);
      return user1;
    }
    @GetMapping("/findByPage")
    public Page<User> findByPage(@RequestParam(value = "pageCode" ,defaultValue = "0")int pageCode,
                                 @RequestParam(value = "pageSize" ,defaultValue = "5")int pageSize) {
        log.info("页码"+pageCode);
        log.info("条数"+pageSize);
        Page<User> userPage= userService.findByPage(pageCode,pageSize);
        System.out.println("数据"+userPage);
        return userPage;
    }

}
